package cn.com.member.controller.match;


import java.util.List;




import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import cn.com.api.entity.ApiU_match_vote;
import cn.com.api.service.ApiU_match_voteService;

import cn.com.util.*;

@Controller
@RequestMapping(Utils.SYS_VIEWS+"/")
public class U_match_voteController  {

	private static Logger logger = Logger.getLogger(U_match_voteController.class);
	
	@Autowired
	private ApiU_match_voteService apiU_match_voteService;
	
	

	/**
	 * 进入新增或者编辑页面
	 * @return
	 */
	@RequestMapping(value = "u_match-vote-info-pre")
	public ModelAndView u_match_vote_info_pre(HttpServletRequest request, HttpServletResponse response) throws Exception{
		ModelAndView mv = new ModelAndView("/match/u_match_vote_list");
		try {
			if(request.getParameter("id") != null){
				String id = request.getParameter("id");
				List<ApiU_match_vote> list_match_vote = apiU_match_voteService.findU_match_voteByWorkId(Integer.valueOf(id));
				mv.addObject("u_match",list_match_vote);
			}
		} catch (Exception e) {
			logger.error("===========[U_match_voteController[u_match_vote_info_pre[获取详情信息失败]]]========", e);
		}
		return mv;
	}
	
	
	/**
	 * 列表
	 * @return
	 */
	@RequestMapping(value = "u_match-vote-detail-list")
	public ModelAndView u_match_vote_list(HttpServletRequest request, HttpServletResponse response) throws Exception{
		ModelAndView mv = new ModelAndView("/match/u_match_vote_detail_list");
		try {
			if(request.getParameter("id") != null){
				String id = request.getParameter("id");
				List<ApiU_match_vote> u_match_detail_votes = apiU_match_voteService.findU_match_votesByWorksId(id);
				mv.addObject("u_match_detail_votes", u_match_detail_votes);
			}
	}catch (Exception e) {
		logger.error("===========[U_match_voteController[u_match_vote_list[获取详情信息失败]]]========", e);
	}
		return mv;		
	}
	
	
	
	/**
	 * 已投票人员
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "u_match-vote-already-list")
	public ModelAndView u_match_vote_already_list(HttpServletRequest request, HttpServletResponse response) throws Exception{
		ModelAndView mv = new ModelAndView("/match/u_match_vote_already_list");
		try {
			if(request.getParameter("id") != null){
				String id = request.getParameter("id");
				String enroll_num = request.getParameter("ext1");
				int vote_num = apiU_match_voteService.findU_vote_numByMatchId(Integer.valueOf(id));
				List<ApiU_match_vote> u_match_votes = apiU_match_voteService.findU_match_votesByMatchId(id);
				mv.addObject("u_match_votes", u_match_votes);
				if(enroll_num == null || enroll_num.equals("")){
					enroll_num = "0";
				}
				
				mv.addObject("enroll_num",enroll_num);
				mv.addObject("vote_num",vote_num);
			}
		}catch (Exception e) {
			logger.error("===========[U_match_voteController[u_match_vote_already_list[获取已投票人员失败]]]========", e);
		}
			return mv;		
		}

	
}



